<template>
	<view class="content">
		<view style="width: 100%;padding: 5rpx 25rpx;color: #aaaaaa;margin-top: 30rpx;">
			发送添加好友申请内容
		</view>
		<view style="width: 100%;padding: 10rpx 25rpx;">
			<u-input style="background: #eeeeee;border-radius: 6rpx;padding: 10rpx;" v-model="message" type="textarea" :border="false" />
		</view>
		
		<view style="width: 100%;padding: 5rpx 25rpx;color: #aaaaaa;margin-top: 30rpx;">
			设置好友备注
		</view>
		<view style="width: 100%;padding: 10rpx 25rpx;">
			<u-input style="background: #eeeeee;border-radius: 6rpx;padding: 10rpx;" v-model="tag" type="text" :border="false" />
		</view>
		
		<view style="width: 100%;padding: 10rpx 25rpx;margin-top: 60rpx;">
			<u-button @click="sendapply" type="primary">发送申请</u-button>
		</view>
	</view>
</template>

<script>
import moment from 'moment'
	export default {
		data(){
			return {
				name:'',
				id:'',
				message:'',
				tag:''
			}
		},
		onLoad({id,name}) {
			this.id = id
			this.name = name
			const user = this.$store.state.user.user
			this.message = `我是${user.name}`
			this.tag = name
		},
		methods:{
			sendapply: async function(){
				const user = this.$store.state.user.user
				const data = {
					fromname:user.name,
					fromid:user.id,
					toname:this.name,
					status:this.id,
					toid:this.id,
					status:"申请中",
					time:moment().valueOf(),
					tag:this.tag,
					message:this.message,
					gid:0
				}
				const ret = await this.$u.post(`friend/friend/adduserapply`,data)
				if(ret.success){
					uni.showToast({
						title:"已发送"
					})
					this.$socket.send({
						type:"touser_friendapply",
						data:{
							to:{
								id:this.id,
								name:this.name
							},
							item:data
						}
					})
					setTimeout(()=>{
						uni.switchTab({
							url:"/pages/friend/index"
						})
					},800)
				}else{
					uni.showToast({
						title:ret.message,
						icon:"none"
					})
				}
			}
		}
	}
</script>

<style>
	page{
		background: #fafafa;
	}
</style>

<style scoped>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		width: 100%;
	}
	
</style>